<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class AboutYou::SDK::Model::FacetManager::DefaultFacetManager - RDoc Documentation</title>

<link href="../../../../fonts.css" rel="stylesheet">
<link href="../../../../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../../../";
</script>

<script src="../../../../js/jquery.js"></script>
<script src="../../../../js/navigation.js"></script>
<script src="../../../../js/search_index.js"></script>
<script src="../../../../js/search.js"></script>
<script src="../../../../js/searcher.js"></script>
<script src="../../../../js/darkfish.js"></script>


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../../../../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../../../../table_of_contents.html#pages">Pages</a>
    <a href="../../../../table_of_contents.html#classes">Classes</a>
    <a href="../../../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-cache_facets">#cache_facets</a>
    
    <li ><a href="#method-i-clear_cache">#clear_cache</a>
    
    <li ><a href="#method-i-empty-3F">#empty?</a>
    
    <li ><a href="#method-i-facet">#facet</a>
    
    <li ><a href="#method-i-facets_by_group_ids">#facets_by_group_ids</a>
    
    <li ><a href="#method-i-load_cached_facets">#load_cached_facets</a>
    
    <li ><a href="#method-i-parse_json">#parse_json</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-AboutYou::SDK::Model::FacetManager::DefaultFacetManager">
  <h1 id="class-AboutYou::SDK::Model::FacetManager::DefaultFacetManager" class="class">
    class AboutYou::SDK::Model::FacetManager::DefaultFacetManager
  </h1>

  <section class="description">
    
<p>This class is responsible for handling all the logic when working with
Facets</p>
<dl class="rdoc-list note-list"><dt>author
<dd>
<p>Collins GmbH &amp; Co KG</p>
</dd></dl>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="DEFAULT_CACHE_DURATION">DEFAULT_CACHE_DURATION
        
        <dd><p>the duration for the cached values to live</p>
        
      
      </dl>
    </section>
    

    
    <section class="attribute-method-details" class="method-section">
      <header>
        <h3>Attributes</h3>
      </header>

      
      <div id="attribute-i-cache" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">cache</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>an Instance of a class of <a
href="../../CacheProvider.html">AboutYou::SDK::CacheProvider</a></p>
        
        </div>
      </div>
      
      <div id="attribute-i-cache_key" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">cache_key</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The key for which the values are stored in the cache</p>
        
        </div>
      </div>
      
      <div id="attribute-i-facets" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">facets</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>a Hash containing instances of <a
href="../Facet.html">AboutYou::SDK::Model::Facet</a></p>
        
        </div>
      </div>
      
      <div id="attribute-i-shop_api" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">shop_api</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>an Instance of <a href="../../../../AY.html">AY</a></p>
        
        </div>
      </div>
      
    </section>
    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(cache = nil, app_id = '', shop_api)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>the Constructor for the <a
href="DefaultFacetManager.html">DefaultFacetManager</a> class</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>cache</code> -&gt; The cache client set on the <a
href="../../../../AY.html">AY</a> class</p>
</li><li>
<p><code>app_id</code> -&gt; The App-Id of the <a href="../App.html">App</a></p>
</li><li>
<p><code>shop_api</code> -&gt; an Instance of <a
href="../../../../AY.html">AY</a></p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of AboutYou::SDK::Model::CategoryManager::DefaultFacetManager</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">cache</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">app_id</span> = <span class="ruby-string">''</span>, <span class="ruby-identifier">shop_api</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">cache</span>     = <span class="ruby-identifier">cache</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">facets</span>    = {}
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">shop_api</span>  = <span class="ruby-identifier">shop_api</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">cache_key</span> = <span class="ruby-string">'AY:SDK:'</span> <span class="ruby-operator">+</span> <span class="ruby-constant">String</span>(<span class="ruby-identifier">app_id</span>) <span class="ruby-operator">+</span> <span class="ruby-string">':facets'</span>

  <span class="ruby-identifier">load_cached_facets</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-cache_facets" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">cache_facets</span><span
            class="method-args">(json_object)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>this method caches a given json_object</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>json_object</code> -&gt; the jsonObject received from the api</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>True/False determining whether the setting was sucessfull or not</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="cache_facets-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 66</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">cache_facets</span>(<span class="ruby-identifier">json_object</span>)
  <span class="ruby-identifier">cache</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">cache_key</span>, <span class="ruby-identifier">json_object</span>, <span class="ruby-constant">DEFAULT_CACHE_DURATION</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-clear_cache" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">clear_cache</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method clears the cache</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>True/False determining whether the clearing was sucessfull or not</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="clear_cache-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 76</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">clear_cache</span>
  <span class="ruby-identifier">cache</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">cache_key</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-empty-3F" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">empty?</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>this method checks whether this facet manager has read-in facets or not</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>a boolean which determines whether this facet Manager has read-in facets or
not</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="empty-3F-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 104</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">empty?</span>
  <span class="ruby-identifier">facets</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-facet" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">facet</span><span
            class="method-args">(group_id, id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for getting a facet model by a given group_id and
facetId</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>group_id</code> -&gt; the group id for which a facet model should be
returned</p>
</li><li>
<p><code>id</code> -&gt; the facet id for which a facet model should be
returned</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>either an instance of <a
href="../Facet.html">AboutYou::SDK::Model::Facet</a> or nil if
<code>group_id</code> or <code>id</code> is not found</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="facet-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 118</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">facet</span>(<span class="ruby-identifier">group_id</span>, <span class="ruby-identifier">id</span>)
  <span class="ruby-identifier">look_up_key</span> = <span class="ruby-constant">AboutYou</span><span class="ruby-operator">::</span><span class="ruby-constant">SDK</span><span class="ruby-operator">::</span><span class="ruby-constant">Model</span><span class="ruby-operator">::</span><span class="ruby-constant">Facet</span>.<span class="ruby-identifier">new</span>(
    <span class="ruby-value">0</span>,
    <span class="ruby-string">''</span>,
    [],
    <span class="ruby-value">0</span>,
    <span class="ruby-string">''</span>
  ).<span class="ruby-identifier">unique_key</span>(<span class="ruby-identifier">group_id</span>, <span class="ruby-identifier">id</span>)
  <span class="ruby-identifier">facets</span>[<span class="ruby-identifier">look_up_key</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">facets</span>[<span class="ruby-identifier">look_up_key</span>] <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-facets_by_group_ids" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">facets_by_group_ids</span><span
            class="method-args">(group_ids = [])</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method is used for getting all facets for an Array of group ids</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>group_ids</code> -&gt; an Array containing group ids for which facet
models should be returned</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>a Hash containing pairs of facetId =&gt; instance of <a
href="../Facet.html">AboutYou::SDK::Model::Facet</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="facets_by_group_ids-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 138</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">facets_by_group_ids</span>(<span class="ruby-identifier">group_ids</span> = [])
  <span class="ruby-identifier">group_ids</span> = <span class="ruby-identifier">group_ids</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">gId</span><span class="ruby-operator">|</span> <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">gId</span>) }
  <span class="ruby-identifier">facets</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">_key</span>, <span class="ruby-identifier">facet</span><span class="ruby-operator">|</span> <span class="ruby-identifier">group_ids</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">facet</span>.<span class="ruby-identifier">group_id</span>) }
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-load_cached_facets" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">load_cached_facets</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Gets the cached Categories for this app</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>True/False determining whether the loading was sucessfull or not</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="load_cached_facets-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 50</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">load_cached_facets</span>
  <span class="ruby-identifier">parse_json</span>(
    <span class="ruby-identifier">cache</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">cache_key</span>),
    <span class="ruby-identifier">shop_api</span>.<span class="ruby-identifier">model_factory_instance</span>
  ) <span class="ruby-keyword">if</span> <span class="ruby-identifier">cache</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">cache</span>.<span class="ruby-identifier">exists</span>(<span class="ruby-identifier">cache_key</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-parse_json" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">parse_json</span><span
            class="method-args">(json_object, factory, query = nil)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>this method parses a json object received from the api and creates models
from it</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>json_object</code> -&gt; the jsonObject received from the api</p>
</li><li>
<p><code>factory</code> -&gt; the model factory used for creating the models</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of AboutYou::SDK::Model::CategoryManager::DefaultFacetManager</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="parse_json-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/Model/FacetManager/default_facet_manager.rb, line 91</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">parse_json</span>(<span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">factory</span>, <span class="ruby-identifier">query</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">facets</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">json_object</span>
  <span class="ruby-identifier">cache_facets</span>(<span class="ruby-identifier">json_object</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">cache</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">facets</span> = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">create_facets_list</span>(<span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">query</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.2.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

